package com.library.service.impl;

import com.library.bean.User;
import com.library.dao.UserDao;
import com.library.dao.impl.UserDaoImpl;
import com.library.service.UserService;

import java.util.HashMap;
import java.util.Map;

public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    @Override
    public int userRegister(User user) {
        User u = userDao.selectUserByUserName(user.getUsername());
        if(u!=null){
            return -1;
        }
        return userDao.insertUser(user);
    }

    @Override
    public Map<String, Object> userLogin(String username,String password) {
        Map<String,Object> map = null;
        User u = userDao.selectUserByUserNameAndPassword(username, password);
        if(u!=null){
           map= new HashMap<String,Object>();
           map.put("success",u);
        }else{
            map= new HashMap<String,Object>();
            u = userDao.selectUserByUserName(username);
            if(u!=null){
                map.put("fail","密码错误");
            }else{
                map.put("fail","账号不存在");
            }
        }
        return map;
    }

}
